package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.FinishedGoods;
import com.ruoyi.mes.service.IFinishedGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成品库存信息Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/mes/goods")
public class FinishedGoodsController extends BaseController
{
    @Autowired
    private IFinishedGoodsService finishedGoodsService;

    /**
     * 查询成品库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('mes:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(FinishedGoods finishedGoods)
    {
        startPage();
        List<FinishedGoods> list = finishedGoodsService.selectFinishedGoodsList(finishedGoods);
        return getDataTable(list);
    }

    /**
     * 导出成品库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('mes:goods:export')")
    @Log(title = "成品库存信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FinishedGoods finishedGoods)
    {
        List<FinishedGoods> list = finishedGoodsService.selectFinishedGoodsList(finishedGoods);
        ExcelUtil<FinishedGoods> util = new ExcelUtil<FinishedGoods>(FinishedGoods.class);
        util.exportExcel(response, list, "成品库存信息数据");
    }

    /**
     * 获取成品库存信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:goods:query')")
    @GetMapping(value = "/{inventoryId}")
    public AjaxResult getInfo(@PathVariable("inventoryId") Long inventoryId)
    {
        return success(finishedGoodsService.selectFinishedGoodsByInventoryId(inventoryId));
    }

    /**
     * 新增成品库存信息
     */
    @PreAuthorize("@ss.hasPermi('mes:goods:add')")
    @Log(title = "成品库存信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FinishedGoods finishedGoods)
    {
        return toAjax(finishedGoodsService.insertFinishedGoods(finishedGoods));
    }

    /**
     * 修改成品库存信息
     */
    @PreAuthorize("@ss.hasPermi('mes:goods:edit')")
    @Log(title = "成品库存信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FinishedGoods finishedGoods)
    {
        return toAjax(finishedGoodsService.updateFinishedGoods(finishedGoods));
    }

    /**
     * 删除成品库存信息
     */
    @PreAuthorize("@ss.hasPermi('mes:goods:remove')")
    @Log(title = "成品库存信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inventoryIds}")
    public AjaxResult remove(@PathVariable Long[] inventoryIds)
    {
        return toAjax(finishedGoodsService.deleteFinishedGoodsByInventoryIds(inventoryIds));
    }
}
